package com.mxnet.chongjin.supoman.activity;

import android.app.Instrumentation;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.google.gson.Gson;
import com.mxnet.chongjin.supoman.R;
import com.mxnet.chongjin.supoman.bean.ApBean;
import com.mxnet.chongjin.supoman.bean.TimeBean;
import com.mxnet.chongjin.supoman.config.Api;
import com.mxnet.chongjin.supoman.style.XDialog;
import com.mxnet.chongjin.supoman.utils.LoggerUtils;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

import okhttp3.Call;

public class AppointTimeActivity extends AppCompatActivity implements View.OnClickListener {
    private Context mContext;
    private LinearLayout mLinearLayout;
    private FrameLayout mLayout1, mLayout2, mLayout3, mLayout4;
    private TextView mTextView1, mTextView2, mTextView3, mTextView4;
    private TextView mButton1, mButton2, mButton3, mButton4, mButton5, mButton6, mButton7;
    private boolean isS1, isS2, isS3, isS4, isS5, isS6, isS7;
    private SharedPreferences mPreferences;
    private SharedPreferences.Editor mEditor;
    private Button mButton;
    private int sequenceNum;
    private String startPwd, MAC;
    private List<String> mStringList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_appoint_time);
        getWindow().getDecorView().setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        getWindow().setStatusBarColor(Color.TRANSPARENT);
        mContext = AppointTimeActivity.this;
        mPreferences = getSharedPreferences("supoman", MODE_PRIVATE);
        mEditor = mPreferences.edit();

        startPwd = mPreferences.getString("startPwd", "FFFFFFFF");
        MAC = mPreferences.getString("MAC", "");

        initData();
        initView();
    }

    public void initData() {
        isS1 = mPreferences.getBoolean("isS1", false);
        isS2 = mPreferences.getBoolean("isS2", false);
        isS3 = mPreferences.getBoolean("isS3", false);
        isS4 = mPreferences.getBoolean("isS4", false);
        isS5 = mPreferences.getBoolean("isS5", false);
        isS6 = mPreferences.getBoolean("isS6", false);
        isS7 = mPreferences.getBoolean("isS7", false);

        mStringList = new ArrayList<>();
    }

    public void initView() {
        mButton = findViewById(R.id.btn_appoint_time);
        mButton.setOnClickListener(this);

        mLinearLayout = findViewById(R.id.ll_appoint_time);
        mLinearLayout.setOnClickListener(this);

        mLayout1 = findViewById(R.id.fl_appoint_time_1);
        mLayout1.setOnClickListener(this);

        int point1 = mPreferences.getInt("point1", 0);

        int point2 = mPreferences.getInt("point2", 0);

        int point3 = mPreferences.getInt("point3", 0);

        mLayout2 = findViewById(R.id.fl_appoint_time_2);
        mLayout2.setOnClickListener(this);
        if (point1 == 0) {
            mLayout2.setVisibility(View.GONE);
        }

        mLayout3 = findViewById(R.id.fl_appoint_time_3);
        mLayout3.setOnClickListener(this);
        if (point2 == 0) {
            mLayout3.setVisibility(View.GONE);
        }

        mLayout4 = findViewById(R.id.fl_appoint_time_4);
        mLayout4.setOnClickListener(this);
        if (point3 == 0) {
            mLayout4.setVisibility(View.GONE);
        }

        mTextView1 = findViewById(R.id.tv_appoint_time_appointment_time);

        mTextView2 = findViewById(R.id.tv_appoint_time_appointment_1);

        mTextView3 = findViewById(R.id.tv_appoint_time_appointment_2);

        mTextView4 = findViewById(R.id.tv_appoint_time_appointment_3);

        mButton1 = findViewById(R.id.btn_appoint_time_monday);
        mButton1.setOnClickListener(this);

        mButton2 = findViewById(R.id.btn_appoint_time_tuesday);
        mButton2.setOnClickListener(this);

        mButton3 = findViewById(R.id.btn_appoint_time_wednesday);
        mButton3.setOnClickListener(this);

        mButton4 = findViewById(R.id.btn_appoint_time_thursday);
        mButton4.setOnClickListener(this);

        mButton5 = findViewById(R.id.btn_appoint_time_friday);
        mButton5.setOnClickListener(this);

        mButton6 = findViewById(R.id.btn_appoint_time_saturday);
        mButton6.setOnClickListener(this);

        mButton7 = findViewById(R.id.btn_appoint_time_sunday);
        mButton7.setOnClickListener(this);

        setButtonView(isS1, mButton1, 1);
        setButtonView(isS2, mButton2, 1);
        setButtonView(isS3, mButton3, 1);
        setButtonView(isS4, mButton4, 1);
        setButtonView(isS5, mButton5, 1);
        setButtonView(isS6, mButton6, 1);
        setButtonView(isS7, mButton7, 1);
    }

    String showText1 = "12", showText2 = "30", showText3 = "60", showText4 = "60", showText5 = "60";

    @Override
    public void onClick(final View v) {
        switch (v.getId()) {
            case R.id.ll_appoint_time:
                new Thread() {
                    public void run() {
                        try {
                            Instrumentation inst = new Instrumentation();
                            inst.sendKeyDownUpSync(KeyEvent.KEYCODE_BACK);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                }.start();
                break;
            case R.id.fl_appoint_time_1:
                XDialog xDialog = new XDialog(mContext, R.layout.xdialog_appointment_time, new int[]{R.id.btn_appoint_time}, new int[]{}, new int[]{R.id.pv_left, R.id.pv_right});
                xDialog.setCanceledOnTouchOutside(true);
                xDialog.setOnXDialogItemClickListener(new XDialog.OnXDialogItemClickListener() {
                    @Override
                    public void OnXDialogItemClick(XDialog xDialog, View view) {
                        switch (view.getId()) {
                            case R.id.btn_appoint_time:
                                mTextView1.setText(showText1 + ":" + showText2);
                                break;
                        }
                        xDialog.dismiss();
                    }
                });
                xDialog.setOnXDialogItemSelectListener(new XDialog.OnXDialogItemSelectListener() {
                    @Override
                    public void OnXialogItemSelect(XDialog xDialog, View view, String text) {
                        switch (view.getId()) {
                            case R.id.pv_left:
                                showText1 = text;
                                break;
                            case R.id.pv_right:
                                showText2 = text;
                                break;
                        }
                    }
                });
                xDialog.show();
                break;
            case R.id.fl_appoint_time_2:
                XDialog xDialog1 = new XDialog(mContext, R.layout.xdialog_appoint_work_time, new int[]{R.id.btn_appoint_work_time}, new int[]{}, new int[]{R.id.pv_work_time});
                xDialog1.setCanceledOnTouchOutside(true);
                xDialog1.setOnXDialogItemClickListener(new XDialog.OnXDialogItemClickListener() {
                    @Override
                    public void OnXDialogItemClick(XDialog xDialog, View view) {
                        switch (view.getId()) {
                            case R.id.btn_appoint_work_time:
                                mTextView2.setText(showText3 + "min");
                                break;
                        }
                        xDialog.dismiss();
                    }
                });
                xDialog1.setOnXDialogItemSelectListener(new XDialog.OnXDialogItemSelectListener() {
                    @Override
                    public void OnXialogItemSelect(XDialog xDialog, View view, String text) {
                        switch (view.getId()) {
                            case R.id.pv_work_time:
                                showText3 = text;
                                break;
                        }
                    }
                });
                xDialog1.show();
                break;
            case R.id.fl_appoint_time_3:
                XDialog xDialog2 = new XDialog(mContext, R.layout.xdialog_appoint_work_time, new int[]{R.id.btn_appoint_work_time}, new int[]{}, new int[]{R.id.pv_work_time});
                xDialog2.setCanceledOnTouchOutside(true);
                xDialog2.setOnXDialogItemClickListener(new XDialog.OnXDialogItemClickListener() {
                    @Override
                    public void OnXDialogItemClick(XDialog xDialog, View view) {
                        switch (view.getId()) {
                            case R.id.btn_appoint_work_time:
                                mTextView3.setText(showText4 + "min");
                                break;
                        }
                        xDialog.dismiss();
                    }
                });
                xDialog2.setOnXDialogItemSelectListener(new XDialog.OnXDialogItemSelectListener() {
                    @Override
                    public void OnXialogItemSelect(XDialog xDialog, View view, String text) {
                        switch (view.getId()) {
                            case R.id.pv_work_time:
                                showText4 = text;
                                break;
                        }
                    }
                });
                xDialog2.show();
                break;
            case R.id.fl_appoint_time_4:
                XDialog xDialog3 = new XDialog(mContext, R.layout.xdialog_appoint_work_time, new int[]{R.id.btn_appoint_work_time}, new int[]{}, new int[]{R.id.pv_work_time});
                xDialog3.setCanceledOnTouchOutside(true);
                xDialog3.setOnXDialogItemClickListener(new XDialog.OnXDialogItemClickListener() {
                    @Override
                    public void OnXDialogItemClick(XDialog xDialog, View view) {
                        switch (view.getId()) {
                            case R.id.btn_appoint_work_time:
                                mTextView4.setText(showText5 + "min");
                                break;
                        }
                        xDialog.dismiss();
                    }
                });
                xDialog3.setOnXDialogItemSelectListener(new XDialog.OnXDialogItemSelectListener() {
                    @Override
                    public void OnXialogItemSelect(XDialog xDialog, View view, String text) {
                        switch (view.getId()) {
                            case R.id.pv_work_time:
                                showText5 = text;
                                break;
                        }
                    }
                });
                xDialog3.show();
                break;
            case R.id.btn_appoint_time_monday:
                if (!isS1) {
                    isS1 = true;
                    mButton1.setBackgroundResource(R.drawable.xdialog_appoint_btn_shape);
                    mButton1.setTextColor(getResources().getColor(R.color.colorWhite));
                } else {
                    isS1 = false;
                    mButton1.setBackgroundResource(R.drawable.appoint_time_btn_shape);
                    mButton1.setTextColor(getResources().getColor(R.color.item_lv_near_machine));
                }
                break;
            case R.id.btn_appoint_time_tuesday:
                if (!isS2) {
                    isS2 = true;
                    mButton2.setBackgroundResource(R.drawable.xdialog_appoint_btn_shape);
                    mButton2.setTextColor(getResources().getColor(R.color.colorWhite));
                } else {
                    isS2 = false;
                    mButton2.setBackgroundResource(R.drawable.appoint_time_btn_shape);
                    mButton2.setTextColor(getResources().getColor(R.color.item_lv_near_machine));
                }
                break;
            case R.id.btn_appoint_time_wednesday:
                if (!isS3) {
                    isS3 = true;
                    mButton3.setBackgroundResource(R.drawable.xdialog_appoint_btn_shape);
                    mButton3.setTextColor(getResources().getColor(R.color.colorWhite));
                } else {
                    isS3 = false;
                    mButton3.setBackgroundResource(R.drawable.appoint_time_btn_shape);
                    mButton3.setTextColor(getResources().getColor(R.color.item_lv_near_machine));
                }
                break;
            case R.id.btn_appoint_time_thursday:
                if (!isS4) {
                    isS4 = true;
                    mButton4.setBackgroundResource(R.drawable.xdialog_appoint_btn_shape);
                    mButton4.setTextColor(getResources().getColor(R.color.colorWhite));
                } else {
                    isS4 = false;
                    mButton4.setBackgroundResource(R.drawable.appoint_time_btn_shape);
                    mButton4.setTextColor(getResources().getColor(R.color.item_lv_near_machine));
                }
                break;
            case R.id.btn_appoint_time_friday:
                if (!isS5) {
                    isS5 = true;
                    mButton5.setBackgroundResource(R.drawable.xdialog_appoint_btn_shape);
                    mButton5.setTextColor(getResources().getColor(R.color.colorWhite));
                } else {
                    isS5 = false;
                    mButton5.setBackgroundResource(R.drawable.appoint_time_btn_shape);
                    mButton5.setTextColor(getResources().getColor(R.color.item_lv_near_machine));
                }
                break;
            case R.id.btn_appoint_time_saturday:
                if (!isS6) {
                    isS6 = true;
                    mButton6.setBackgroundResource(R.drawable.xdialog_appoint_btn_shape);
                    mButton6.setTextColor(getResources().getColor(R.color.colorWhite));
                } else {
                    isS6 = false;
                    mButton6.setBackgroundResource(R.drawable.appoint_time_btn_shape);
                    mButton6.setTextColor(getResources().getColor(R.color.item_lv_near_machine));
                }
                break;
            case R.id.btn_appoint_time_sunday:
                if (!isS7) {
                    isS7 = true;
                    mButton7.setBackgroundResource(R.drawable.xdialog_appoint_btn_shape);
                    mButton7.setTextColor(getResources().getColor(R.color.colorWhite));
                } else {
                    isS7 = false;
                    mButton7.setBackgroundResource(R.drawable.appoint_time_btn_shape);
                    mButton7.setTextColor(getResources().getColor(R.color.item_lv_near_machine));
                }
                break;
            case R.id.btn_appoint_time:
                mEditor.putBoolean("isS1", isS1);
                if (isS1) {
                    mStringList.add("monday");
                }
                mEditor.putBoolean("isS2", isS2);
                if (isS2) {
                    mStringList.add("tuesday");
                }
                mEditor.putBoolean("isS3", isS3);
                if (isS3) {
                    mStringList.add("wednesday");
                }
                mEditor.putBoolean("isS4", isS4);
                if (isS4) {
                    mStringList.add("thursday");
                }
                mEditor.putBoolean("isS5", isS5);
                if (isS5) {
                    mStringList.add("friday");
                }
                mEditor.putBoolean("isS6", isS6);
                if (isS6) {
                    mStringList.add("saturday");
                }
                mEditor.putBoolean("isS7", isS7);
                if (isS7) {
                    mStringList.add("sunday");
                }
                mEditor.commit();
                final int point1 = mPreferences.getInt("point1", 0);
                final int point2 = mPreferences.getInt("point2", 0);
                final int point3 = mPreferences.getInt("point3", 0);
                List<ApBean> list = new ArrayList();
                if (point1 == 0) {

                } else if (point2 == 0) {
                    ApBean ap1 = new ApBean();
                    ap1.setId(mPreferences.getString("point1Id", ""));
                    ap1.setWorkTime(mTextView2.getText().toString());
                    list.add(ap1);
                } else if (point3 == 0) {
                    ApBean ap1 = new ApBean();
                    ap1.setId(mPreferences.getString("point1Id", ""));
                    ap1.setWorkTime(mTextView2.getText().toString());
                    list.add(ap1);

                    ApBean ap2 = new ApBean();
                    ap2.setId(mPreferences.getString("point2Id", ""));
                    ap2.setWorkTime(mTextView3.getText().toString());
                    list.add(ap2);
                } else {
                    ApBean ap1 = new ApBean();
                    ap1.setId(mPreferences.getString("point1Id", ""));
                    ap1.setWorkTime(mTextView2.getText().toString());
                    list.add(ap1);

                    ApBean ap2 = new ApBean();
                    ap2.setId(mPreferences.getString("point2Id", ""));
                    ap2.setWorkTime(mTextView3.getText().toString());
                    list.add(ap2);

                    ApBean ap3 = new ApBean();
                    ap3.setId(mPreferences.getString("point3Id", ""));
                    ap3.setWorkTime(mTextView4.getText().toString());
                    list.add(ap3);
                }
                // 向服务器发送预约时间信息
                TimeBean timeBean = new TimeBean();
                timeBean.setMac(MAC.toUpperCase());
//                timeBean.setMac();
                timeBean.setAppointTime(mTextView1.getText().toString());
                timeBean.setAppointWeekDayList(mStringList);
                timeBean.setId(mPreferences.getString("appointId", ""));
                timeBean.setApBeans(list);
                OkHttpUtils.get()
                        .url(Api.URL_HEADER + Api.SET_APPOINT)
                        .addParams("data", new Gson().toJson(timeBean))
                        .build().execute(new StringCallback() {
                    @Override
                    public void onError(Call call, Exception e, int id) {

                    }

                    @Override
                    public void onResponse(String response, int id) {
                        if (!TextUtils.isEmpty(response)) {
                            LoggerUtils.i("********", response);
                            try {
                                JSONObject jsonObject = new JSONObject(response);
                                boolean success = jsonObject.optBoolean("success");
                                if (success) {
                                    JSONObject data = jsonObject.optJSONObject("data");
                                    String appointId = data.optString("id");
                                    mEditor.putString("appointId", appointId);
                                    mEditor.commit();
                                }
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                    }
                });

//                final LoadingDailog.Builder loadBuilder = new LoadingDailog.Builder(mContext)
//                        .setMessage(getResources().getString(R.string.excuting))
//                        .setCancelable(true)
//                        .setCancelOutside(true);
//                new Thread(new Runnable() {
//                    @Override
//                    public void run() {
//                        sequenceNum = mPreferences.getInt("sequenceNum", 1);
//                        String seq = getSeq(Integer.toHexString(sequenceNum));
//                        // 根据记忆点数不同，发送不同指令
//                        if (point1 == 0) {
//                            // 没有记忆点时，默认发送记忆点为5秒，并工作120分钟
//                            String p = "050078";
//                            TCPUtils.TCP_sendMsg(Api.SERVER_IP, Api.SERVER_PORT, StringUtils.hexStringToBytes(Api.HEAD + MAC + Api.MY_MAC + startPwd + seq + Api.APPOINT + "01" + p));
//                        } else if (point2 == 0) {
//                            String p1 = getSeqp(getSeq(Integer.toHexString(point1 & 0xFFFF))) + getP(Integer.toHexString(Integer.parseInt(showText3) & 0xFF));
//                            TCPUtils.TCP_sendMsg(Api.SERVER_IP, Api.SERVER_PORT, StringUtils.hexStringToBytes(Api.HEAD + MAC + Api.MY_MAC + startPwd + seq + Api.APPOINT + "01" + p1));
//                        } else if (point3 == 0) {
//                            String p2 = getSeqp(getSeq(Integer.toHexString(point1 & 0xFFFF))) + getSeqp(getSeq(Integer.toHexString(point2 & 0xFFFF))) + getP(Integer.toHexString(Integer.parseInt(showText3) & 0xFF)) + getP(Integer.toHexString(Integer.parseInt(showText4) & 0xFF));
//                            TCPUtils.TCP_sendMsg(Api.SERVER_IP, Api.SERVER_PORT, StringUtils.hexStringToBytes(Api.HEAD + MAC + Api.MY_MAC + startPwd + seq + Api.APPOINT + "02" + p2));
//                        } else {
//                            String p3 = getSeqp(getSeq(Integer.toHexString(point1 & 0xFFFF))) + getSeqp(getSeq(Integer.toHexString(point2 & 0xFFFF))) + getSeqp(getSeq(Integer.toHexString(point3 & 0xFFFF))) + getP(Integer.toHexString(Integer.parseInt(showText3) & 0xFF)) + getP(Integer.toHexString(Integer.parseInt(showText4) & 0xFF)) + getP(Integer.toHexString(Integer.parseInt(showText5) & 0xFF));
//                            TCPUtils.TCP_sendMsg(Api.SERVER_IP, Api.SERVER_PORT, StringUtils.hexStringToBytes(Api.HEAD + MAC + Api.MY_MAC + startPwd + seq + Api.APPOINT + "03" + p3));
//                        }
//                    }
//                }).start();
//                // 设置弹窗
//                final LoadingDailog dialog = loadBuilder.create();
//                dialog.setCancelable(false);   //是否能取消弹窗
//                dialog.show();
//                // 设置一个倒计时，请求命令执行结果，每隔1秒请求一次，共等待5秒
//                // 不管成功失败，5秒后关闭弹窗
//                final CountDownTimer countDownTimer = new CountDownTimer(5 * 1000, 1000) {
//                    @Override
//                    public void onTick(long millisUntilFinished) {
//                        final String seq = getSeq(Integer.toHexString(mPreferences.getInt("sequenceNum", 1)));
//                        OkHttpUtils.get()
//                                .url(Api.URL_HEADER + Api.QUERY_CODE_STATUS)
//                                .addParams("macKey", MAC)
//                                .addParams("sequence", seq)
//                                .build()
//                                .execute(
//                                        new StringCallback() {
//                                            @Override
//                                            public void onError(Call call, Exception e, int id) {
////                                                        ToastUtils.showToast(mContext, getResources().getString(R.string.net_fault));
//                                            }
//
//                                            @Override
//                                            public void onResponse(String response, int id) {
//                                                if (!TextUtils.isEmpty(response)) {
//                                                    try {
//                                                        JSONObject jsonObject = new JSONObject(response);
//                                                        boolean success = jsonObject.optBoolean("success");
//                                                        if (success) {
//                                                            JSONObject data = jsonObject.optJSONObject("data");
//                                                            if (data != null) {
//                                                                String memo = data.optString("memo");
//                                                                String sequence = data.optString("sequence");
//                                                                if (!TextUtils.isEmpty(memo) && seq.toUpperCase().equals(sequence)) {
//                                                                    if (memo.substring(memo.length() - 2, memo.length()).equals("01")) {
//                                                                        if ((sequenceNum + 1) > 65534) {
//                                                                            sequenceNum = 0;
//                                                                            mEditor.putInt("sequenceNum", sequenceNum);
//                                                                            mEditor.commit();
//                                                                        } else {
//                                                                            mEditor.putInt("sequenceNum", sequenceNum + 1);
//                                                                            mEditor.commit();
//                                                                        }
//                                                                        dialog.dismiss();
//                                                                        cancel();
//                                                                        ToastUtils.showToast(mContext, getResources().getString(R.string.control_success));
//
//                                                                    } else if (memo.substring(memo.length() - 2, memo.length()).equals("00")) {
//                                                                        if ((sequenceNum + 1) > 65534) {
//                                                                            sequenceNum = 0;
//                                                                            mEditor.putInt("sequenceNum", sequenceNum);
//                                                                            mEditor.commit();
//                                                                        } else {
//                                                                            mEditor.putInt("sequenceNum", sequenceNum + 1);
//                                                                            mEditor.commit();
//                                                                        }
//                                                                        dialog.dismiss();
//                                                                        cancel();
//                                                                        ToastUtils.showToast(mContext, getResources().getString(R.string.control_failed));
//
//                                                                    }
//                                                                }
//                                                            } else {
//
//                                                            }
//                                                        }
//                                                    } catch (Exception e) {
//                                                        e.printStackTrace();
//                                                    }
//                                                }
//                                            }
//                                        }
//                                );
//                    }
//
//                    @Override
//                    public void onFinish() {
//                        dialog.dismiss();
//                        if ((sequenceNum + 1) > 65534) {
//                            sequenceNum = 0;
//                            mEditor.putInt("sequenceNum", sequenceNum);
//                            mEditor.commit();
//                        } else {
//                            mEditor.putInt("sequenceNum", sequenceNum + 1);
//                            mEditor.commit();
//                        }
//                        ToastUtils.showToast(mContext, getResources().getString(R.string.no_response));
//                        back();
//                    }
//                };
//                countDownTimer.start();
//                break;
        }
    }

    private void back() {
        new Thread() {
            public void run() {
                try {
                    Instrumentation inst = new Instrumentation();
                    inst.sendKeyDownUpSync(KeyEvent.KEYCODE_BACK);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }.start();
    }

    public void setButtonView(boolean b, TextView t, int type) {
        if (type == 0) {
            if (!b) {
                b = true;
                t.setBackgroundResource(R.drawable.xdialog_appoint_btn_shape);
                t.setTextColor(getResources().getColor(R.color.colorWhite));
            } else {
                b = false;
                t.setBackgroundResource(R.drawable.appoint_time_btn_shape);
                t.setTextColor(getResources().getColor(R.color.item_lv_near_machine));
            }
        } else if (type == 1) {
            if (b) {
                t.setBackgroundResource(R.drawable.xdialog_appoint_btn_shape);
                t.setTextColor(getResources().getColor(R.color.colorWhite));
            } else {
                t.setBackgroundResource(R.drawable.appoint_time_btn_shape);
                t.setTextColor(getResources().getColor(R.color.item_lv_near_machine));
            }
        }
    }

    public String getSeq(String seq) {
        if (seq.length() == 1) {
            seq = "000" + seq;
        } else if (seq.length() == 2) {
            seq = "00" + seq;
        } else if (seq.length() == 3) {
            seq = "0" + seq;
        }
        return seq;
    }

    public String getSeqp(String seq) {
        return seq.substring(2, 4) + seq.substring(0, 2);
    }

    public String getP(String str) {
        if (str.length() == 1) {
            str = "0" + str;
        }
        return str;
    }
}
